<?php

class galaxyException extends Exception {
	protected $type,$e,$fwd;
	public function __construct($message, $fwd, $e=null) {		
    parent::__construct($message,0);    
    $this->type = get_class($this);
    $this->e = $e;
    $this->fwd = $fwd;

    $traceInfo = $this->getTrace();
    array_shift($traceInfo);
    $this->class = $traceInfo[0]['class'];
    $this->function = $traceInfo[0]['function'];
    $this->file = $traceInfo[0]['file'];
    $this->line = $traceInfo[0]['line'];
    $file = file($this->file);
    $trace = '';
    $time = date("y-m-d H:i:m");
    foreach($traceInfo as $t) {
        $trace .= '['.$time.'] '.$t['file'].' ('.$t['line'].') ';
        $trace .= $t['class'].$t['type'].$t['function'].'(';
        $trace .= implode(', ', $t['args']);
        $trace .=")\n";
    }
    $this->trace = $trace;
    
    $detail  = L('_MODULE_').'['.MODULE_NAME.'] '.L('_ACTION_').'['.ACTION_NAME.']'."\n";
    $detail .= ($this->line-2).': '.$file[$this->line-3];
    $detail .= ($this->line-1).': '.$file[$this->line-2];
    $detail .= '<font color="#FF6600" >'.($this->line).': <b>'.$file[$this->line-1].'</b></font>';
    $detail .= ($this->line+1).': '.$file[$this->line];
    $detail .= ($this->line+2).': '.$file[$this->line+1];
    $this->detail = $detail;

	}
	public function getError() {
		$error = array();
		foreach(array('message','fwd','type','e','class','function','file','line','trace','detail') as $v) {
			$error[$v] = $this->$v;
		}
		$this->writeLog();
		return $error;
	}
	protected function writeLog() {
		Log::Write(" (".$this->type.")\t".$_ENV['onlineip']."\t".$this->message);
	}
}

?>